#include<Windows.h>
#include"resource.h"
BOOL g_bOpaque=TRUE;
const char g_szClassName[]="myWindowClass";
HWND g_hToolbar=NULL;
BOOL CALLBACK AboutDlfProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
	switch(msg)
	{
	case WM_INITDIALOG:
		return FALSE;
	case WM_COMMAND:
		{
			switch (LOWORD(wParam))
			{
			case IDC_PRESS:
				MessageBox(hwnd,"Press","Note",MB_OK|MB_ICONEXCLAMATION);
				break;
			case IDC_OTHER:
				EndDialog(hwnd,IDC_OTHER);
				MessageBox(hwnd,"Other","Note",MB_OK|MB_ICONEXCLAMATION);
				break;
			}
		}
		break;
	default:
		return FALSE;
	}
	return TRUE;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
	switch(msg)
	{
	case WM_CREATE:
		{
			HICON hIcon,hIconSm;
			HMENU hMenu,hMenuSub;

			hMenu=CreateMenu();

			hMenuSub=CreatePopupMenu();
			AppendMenu(hMenuSub,MF_STRING,ID_FILE_EXIT,"&Exit");
			AppendMenu(hMenu,MF_STRING|MF_POPUP,(UINT)hMenuSub,"&File");

			hMenuSub=CreatePopupMenu();
			AppendMenu(hMenuSub,MF_STRING,ID_DIALOG_SHOW,"&show");
			AppendMenu(hMenuSub,MF_STRING,ID_DIALOG_HIDE,"&hide");
			AppendMenu(hMenu,MF_STRING|MF_POPUP,(UINT)hMenuSub,"&Dialog");

			SetMenu(hwnd,hMenu);

			hIcon=(HICON)LoadImage(NULL,"my_icon.ico",IMAGE_ICON,32,32,LR_LOADFROMFILE);
			if(hIcon)
				SendMessage(hwnd,WM_SETICON,ICON_BIG,(LPARAM)hIcon);
			else
				MessageBox(hwnd,"Failed","hIcon",MB_OK|MB_ICONERROR);
			hIconSm=(HICON)LoadImage(NULL,"my_icon.ico",IMAGE_ICON,16,16,LR_LOADFROMFILE);
			if(hIconSm)
				SendMessage(hwnd,WM_SETICON,ICON_SMALL,(LPARAM)hIconSm);
			else
				MessageBox(hwnd,"Failed!","hIconSm",MB_OK|MB_ICONERROR);
			g_hToolbar=CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_TOOLBAR),hwnd,AboutDlfProc);
			if(g_hToolbar)
				ShowWindow(g_hToolbar,SW_HIDE);
			else 
				MessageBox(hwnd,"failed!","warning",MB_OK|MB_ICONINFORMATION);
		}
		break;
	case WM_COMMAND:
		{
			switch (LOWORD(wParam))
			{
			case ID_FILE_EXIT:
				SendMessage(hwnd,WM_CLOSE,0,0);
				break;
			case ID_DIALOG_HIDE:
				ShowWindow(g_hToolbar,SW_HIDE);
				break;
			case ID_DIALOG_SHOW:
				ShowWindow(g_hToolbar,SW_SHOW);
				break;
			}
		}
		break;
	case WM_LBUTTONDOWN:
		{
			char szFileName[MAX_PATH];
			HINSTANCE hInstance=GetModuleHandle(NULL);
			GetModuleFileName(hInstance,szFileName,MAX_PATH);
			MessageBox(hwnd,szFileName,"This program is:",MB_OK|MB_ICONINFORMATION);
		}
		break;
	case WM_CLOSE:
		DestroyWindow(hwnd);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hwnd,msg,wParam,lParam);
	}
	return 0;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdLine)
{
	WNDCLASSEX wc;
	wc.cbClsExtra=0;
	wc.cbSize=sizeof(WNDCLASSEX);
	wc.cbWndExtra=0;
	wc.hbrBackground=(HBRUSH)(COLOR_WINDOW);
	wc.hCursor=LoadCursor(NULL,IDC_ARROW);
	wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
	wc.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
	wc.hInstance=hInstance;
	wc.lpfnWndProc=WndProc;
	wc.lpszClassName=g_szClassName;
	wc.lpszMenuName=NULL;
	wc.style=0;
	if(!RegisterClassEx(&wc))
	{
		MessageBox(NULL,"Failed!","Note 1",MB_OK|MB_ICONEXCLAMATION);
		return 0;
	}
	HWND hwnd;
	hwnd=CreateWindowEx(WS_EX_CLIENTEDGE,g_szClassName,"Title",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,500,500,NULL,NULL,hInstance,NULL);
	if(!hwnd)
	{
		MessageBox(NULL,"Failed!","Note 1",MB_OK|MB_ICONEXCLAMATION);
		return 0;
	}
	ShowWindow(hwnd,nCmdLine);
	UpdateWindow(hwnd);
	MSG msg;
	while(GetMessage(&msg,NULL,0,0)>0)
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return msg.wParam;

}